#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef pair<LL, int> PII;
#define x first
#define y second
const int N = 1e5 + 10, M = N * 2;
int h[N], e[M], ne[M], idx;
LL w[M];
LL dis1[N], dis2[N];
bool st[N];
int n, m;
int ans;
LL x;
LL ma;
void add(int a, int b, LL c)
{
	e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
}
void dij(int x)
{
	priority_queue<PII, vector<PII>, greater<PII>>heap;
	heap.push({ 0,x });
	for (int i = 1; i <= n; i++) {
		dis1[i] = 1e15;
	}
	dis1[x] = 0;
	while (heap.size()) {
		PII t = heap.top();
		heap.pop();
		LL distance = t.x;
		int ver = t.y;
		if (st[ver])continue;
		st[ver] = 1;
		for (int i = h[ver]; ~i; i = ne[i]) {
			int j = e[i];
			if (dis1[j] > distance + w[i]) {
				dis1[j] = distance + w[i];
				if (ma < w[i] && j != n && ver != 1) {
					ma = w[i];
					ans = j;
				}
				heap.push({ dis1[j],j });
			}
		}
	}
}
void dij1(int x)
{
	priority_queue<PII, vector<PII>, greater<PII>>heap;
	memset(st, 0, sizeof(st));
	heap.push({ 0,x });
	for (int i = 1; i <= n; i++) {
		dis2[i] = 1e15;
	}
	dis2[x] = 0;
	while (heap.size()) {
		PII t = heap.top();
		heap.pop();
		LL distance = t.x;
		int ver = t.y;
		if (st[ver])continue;
		st[ver] = 1;
		for (int i = h[ver]; ~i; i = ne[i]) {
			int j = e[i];
			if (dis2[j] > distance + w[i]) {
				dis2[j] = distance + w[i];
				heap.push({ dis2[j],j });
			}
		}
	}
}
int main()
{
	scanf("%d%d%lld", &n, &m, &x);
	memset(h, -1, sizeof(h));
	while (m--) {
		int a, b;
		LL c;
		scanf("%d%d%lld", &a, &b, &c);
		add(a, b, c);
		add(b, a, c);
	}
	dij(1);
	if (dis1[n] != 1e15) {
		if (ma < x) {
			printf("%lld\n", dis1[n]);
		}
		else {
			printf("%lld\n", dis1[n] - ma + x);
		}
	}
	else {
		dij1(n);
		LL mi1 = 1e15, mi2 = 1e15;
		for (int i = 2; i <= n - 1; i++) {
			mi1 = min(mi1, dis1[i]);
		}
		for (int i = 2; i <= n - 1; i++) {
			mi2 = min(mi2, dis2[i]);
		}
		//cout << "mi1==" << mi1 << endl;
		//cout << "mi2==" << mi2 << endl;
		if (mi1 != 1e15 && mi2 != 1e15) {
			printf("%lld\n", mi1 + mi2 + x);
		}
		else printf("-1\n");
	}
	return 0;
}
/*
4 5 1
1 2 3
1 3 2
2 3 1
3 4 4
4 2 1

1 2 3
2 4 1
4 
*/